<?php
  // Import js & css for the Sliding Form
  $options = array('inline'=>false);
  echo $this->Html->script('libs/SlidingForm/sliding_form.js',$options);
  echo $this->Html->css("/js/libs/SlidingForm/sliding_form.css",null,$options);
  
  echo $this->Html->css("menu_tight",null,$options);
?>

<!-- Job heading to be displayed if only adding new JobVersion -->
<?php if( !$addNewJob && !$editJob): ?>
<div class="panel" id="WrapperPanel">
  <div class="panel">
  <?php /*debug($job);*/ ?>
  <!--
  <h2>Job: <?=  $job['Job']['name']; ?></h2>
  
  <table>
    <tr>
      <th>Group</th>
      <th>Alternate Job Name</th>
      <th>Description</th>
			<th>Created</th>
    </tr>
    <tr>
      <td><?php /*echo $job['JobGroup']['name']*/ ?>&nbsp;</td>
      <td><?php /*echo $job['JobAltName']['name'] */?>&nbsp;</td>
      <td><?php /*echo $job['Description']['content'] */?>&nbsp;</td>
      <td><?php /*echo $job['Job']['created']; */?>&nbsp;</td>
    </tr>
  </table>
  -->
  
  <!-- Job Details (group, name, alt name, descrip, etc) -->
  <dl>
    <div id="jobNameDiv">
      <dt class="heading">Job</dt>
      <dd ><strong><h3 id="jobName"><?php echo $job['Job']['name']; ?></h3></strong></dd>
      <a id="showJobDetailsLink">show details</a>
    </div>
    <div id="jobDetails">
      <div class="altrow">
        <dt>Group</dt>
        <dd><?php echo $job['JobGroup']['name']; ?></dd>
      </div>

      <?php // Alternate Job Name 
      if(isset($job['JobAltName']['name'])): ?>
      <dt>Alternate Name</dt>
      <dd><?php echo "{$job['JobAltName']['name']}"; ?></dd>
      <?php endif; ?>

      <?php // Description
      if(isset($job['Description']['content'])): ?>
      <div class="altrow">
        <dt>Description</dt>
        <dd id="description"><?php echo "{$job['Description']['content']}"; ?></dd>
      </div>
      <?php endif; ?>  
    </div>
  </dl>
  </div> <!-- end nested panel -->
<!--</div> <!-- end panel -->
<?php endif; ?>

<div class="jobs form">
  
<?php  // the 'url' param of create() lets me pass the state vars back to the conroller again 
echo $this->Form->create('Job', array('url' => array($job_id, 
                                                     $template_version_id, 
                                                     $edit_job_id, 
                                                     $edit_version_id) ));
?>
  <div id="accordianWrapper">
  <?php 
  //////////////////////////////////////////////////////////////////////
  /////////////// JOB Fields ///////////////////////////////////////////
  if($addNewJob || $editJob):
  ?>
    
  <h3  id="jobLegend" class="accordianLegend"> <!-- header for an accordian tab -->
    <a href="#"><?php echo $addNewJob ? 'Add Job' : 'Edit Job'; ?></a>
  </h3>
    
  <!-- content of an accordian panel -->
  <div id="jobFieldset" class="addFieldset"> 
  <!--
	<fieldset id="jobFieldset">
		<legend> <?php /*echo $addNewJob ? 'Add Job' : 'Edit Job'; */?></legend>
  -->
    <?php
    // <editor-fold defaultstate="collapsed" desc="Id's for Job">
    if ($editJob) {
      echo $this->Form->input('id');
      echo $this->Form->input('JobAltName.id');
      echo $this->Form->input('Description.id');
    }// </editor-fold>

    // --------------------------------------------------------------
    // Selector widget for selecting Job Group and Job Name: 
    ?>
    <div class="required">
      <label for="jobGroupSelector">Job Group and Job directory</label>
      <p class="guidance">Select group panel, then job dir</p>
    </div>
    <div id="jobGroupSelector">
      <?php      
      foreach ($jobGroupsAndJobs as $jobGroupName => $jobGroupArray) :   
        // provide a way to have a certain panel open on load (controller sets it)
        if(isset($this->data['Job']['job_group_id'])
             && $jobGroupArray['id'] == $this->data['Job']['job_group_id']) {
          $panelId = 'open_panel'; $panelAnchorHref = '#open';
        }
        else {
          $panelId = '';  $panelAnchorHref = '#';
        }
      ?>
        <!-- the h3 and the div must be direct siblings for the Accordian to work (unless you set a diff header) -->
        <h3  id="<?=$panelId ?>">
          <a href="<?=$panelAnchorHref ?>"><?=$jobGroupName ?></a>
        </h3>

        <div>
          <?php 
          // I'm including some custom html attributes for each radio in this job group 
          // to hold data that applies to all jobs in this job group (I'm using jQuery to extract those vals)
          $radioGroupAttributes = array('legend' => false,
                                        'hiddenField'=>false,
                                        'class'=>'jobNameRadios',
                                        // custom attributes:
                                        'data-jobGroup'=>$jobGroupName, 
                                        'data-jobGroupId'=>$jobGroupArray['id'],
                                        'data-jobGroupFullPath'=>$jobGroupArray['groupAbsPath'] 
                                       );
          $jobNamesKeyAndVal = array();
          foreach($jobGroupArray['jobDirs'] as $jobName) {
            $jobNamesKeyAndVal[$jobName] = $jobName;
          }
          echo $this->Form->radio('dir_name', $jobNamesKeyAndVal, $radioGroupAttributes);
          ?>
        </div>
      <?php
      endforeach;  
      ?>
    </div> <!-- end #jobGroupSelector div -->
    
    <div id="groupHelpfulLinkWrapper">
      <p>Don't see your Job Group?  
      <?php echo $this->Html->link('Add one now.', array('controller'=>'job_groups', 'action'=>'form')); ?>
      </p>
    </div>
    
    <?php
    //// ------------------------------------------------------------------------
    //// '.secondaryJobStuff' div (hide until a job group & dir has been selected
    ?>
    <div class="<?php echo($addNewJob && $validated ? 'secondaryJobStuff' : ''); ?>" >
    
    <?php 
                //echo $this->Form->input('job_group', array('type'=>'text'));
      // Job Group    //(one hidden and one disabled - val supplied by jQuery)
          //echo $this->MyForm->dynamicInputsDisabledAndHidden('Job.job_group', 'JobJobGroupDiv', 'text');
      echo $this->Form->input('Job.job_group_id', array('type'=>'hidden')); // val gets set by jQuery
      
      // Job Name
      echo $this->Form->input('name' /*, array('after'=>'<p class="guidance">Must be unique</p>')*/);
      // Job Alt Name
      echo $this->Form->input('JobAltName.name', array('label'=>'Alternate Job Name',
                                                       'div' => 'override_required'));
      // Job Dir Name
            //echo $this->Form->input('dir_name', array('label'=>'Job Directory Name'));
      $options = array('label'=>'Directory Name');
      echo $this->MyForm->dynamicInputsDisabledAndHidden('Job.dir_name', 'JobDirNameDiv', 'text',$options);
            // Job Absolute Path - now only stored in job group
            //$guidance = "<p class='guidance'>Include the job's dir, but not a trailing '/'. Example: /home/myJobDir</p>";
            //$options = array('label'=>'Absolute path of Job Directory', 'after'=>$guidance);
            //echo $this->MyForm->dynamicInputsDisabledAndHidden('Job.dir_abs_path','JobDirAbsPathDiv','text',$options);
      // Description
      echo $this->Form->input('Description.content', array('label'=>'Job Description',
                                                           'rows' =>'2',
                                                            // Add a CSS class to basically remove 'required' class:
                                                            'div' => 'override_required'));
      echo $form->input('Tag.name',array(
      //echo $form->input('JobsTag.Tag.name',array(
                          'type' => 'textarea',
                          'rows' => '1',
                          'label' => 'Tags',
                          'after' => '<span class="guidance">'
                                 .'Seperate each tag with a comma.  Eg: family, sports, icecream</span>',
                          'div' => 'override_required'));
    echo '</div>'; /// end '.secondaryJobStuff' div ///
    ?>
	
  <!--</fieldset> <!-- end jobFieldset -->
  </div> <!-- end #jobFieldset -->
  
  <?php endif; // end if($addNewJob || $editJob) 
  //////////////////////////////////////////////////////////////////////////////
  /////////////// JOB VERSION Fields ///////////////////////////////////////////
  if($addNewJobVersion || $editJobVersion):
    $verNum = 0;
    $commentNum = 0;
  ?>
  
  <!-- header for an accordian tab -->
  <h3  id="jobVersionLegend" class="accordianLegend <?php echo (($addNewJob && $validated) ? 'secondaryJobStuff' : ''); ?>"> 
    <a href="#"><?php echo $addNewJobVersion ? 'Add Job Version' : 'Edit Job Version'; ?></a>
  </h3>
  
  <div id="jobVersionFieldset" class="addFieldset" >
    
  <!-- now using a div for this fieldset (for accordian and so FF would obey width CSS for sliding form)
  <fieldset id="jobVersionFieldset" <?php /* echo (($addNewJob && $validated) ? 'class="secondaryJobStuff"' : "");*/?> >  
    <legend> <?php /* echo $addNewJobVersion ? 'Add Job Version' : 'Edit Job Version';*/ ?></legend>
  -->
  
  
  
  
    <ul id="fijiMenu" class="menuTight shadow2">
    <?php
      // "Launch Fiji" menu item (Launch INPUT projections preview)
    
      // define some empty vars for passing to method for code readability (rather than passing 'null')
      $linkArgs     = null;  $separateArgs = null;   $subList = null;  $confirmMsg = null;
      $linkOptions = array();   $imgOptions =  array('class'=>'icon');  $itemTooltip = null;
      
      $isFirstTopMenuItem = true; $isLastTopMenuItem  = true;
      // NOTE: Don't name the tooltip var as '$tooltip'. It confuses Cake at the end of the form where
      //     I use a helper named "Tooltip". It throws a non-object pointer error!      
      $linkDisplayStr = 'Launch Fiji';   
      $iconPath = 'Icons/White/NoCircle/32x32/taskmgr.png'; 
      $linkToController = '';         $linkToMethod = '';      $linkArgs = array();
      // I'm including some custom html attributes for each 'launch fiji' btn so that data
      // can be extracted via jQuery and used in an Ajax call to get approp images to open in fiji. 
      $linkOptions['class'] = 'fiji';
      $linkOptions['id']    = 'fijiInputDataLaunchBtn';
      $linkOptions['data-is_input_data_preview'] = 'true'; 
      if($addNewJob) {
        $itemTooltip = 'Examine a set of projections from the original input data';
        // NOTE: 3 other data attributes get added to this element via jQuery once the user
        //   has selected which job directory they want for this new job.
      }
      else {
        $linkOptions['data-job_id'] = $job['Job']['id'];
        $itemTooltip = 'Examine a set of projections from the input data';
      }
      echo $this->Menu->makeListItem($linkToController, $linkToMethod, $linkArgs, $separateArgs,
                            $isFirstTopMenuItem,$isLastTopMenuItem, $linkDisplayStr, $itemTooltip, 
                            $iconPath, $subList, $linkOptions, $imgOptions, $confirmMsg );
    ?>
    </ul>  
  
  
  
    <div id="steps"> <!-- outer wrapper for sliding form -->
     <div id="slidingFormFieldsetDiv"> <!-- maps to orig's "#formElem" -->
    
      <fieldset id="jobVersionGeneralFieldset" class="step tab-general">
        <legend>General</legend>
        <?php
          // <editor-fold defaultstate="collapsed" desc="Version Id's">
          // Job id's (so adding new version or editing version won't try to save a new Job)
          if( !$addNewJob) { // don't include id field if adding entire new job
            echo $this->Form->input('id');
          }
          if (isset($this->data['JobAltName']['id'])) {
            echo $this->Form->input('JobAltName.id');
          }
          if (isset($this->data['Description']['id'])) {
            echo $this->Form->input('Description.id');
          }
          // JobVersion id's 
          if ($editJobVersion) {
            echo $this->Form->input("JobVersion.$verNum.id");

            if (isset($this->data['JobVersionName']['id'])) {
              echo $this->Form->input("JobVersionName.id");
            }
            if (isset($this->data['JobVersionComment'][$commentNum]['id'])) {
              echo $this->Form->input("JobVersionComment.$commentNum.id");
            }
            if (isset($this->data['CudaJob']['id'])) {
              echo $this->Form->input("CudaJob.id");
            }
            if (isset($this->data['ParamFdkBasis']['id'])) {
              echo $this->Form->input("ParamFdkBasis.id");
            }
            if (isset($this->data['ParamSirtBasis']['id'])) {
              echo $this->Form->input("ParamSirtBasis.id");
            }
            if (isset($this->data['ParamImageRoiZ']['id'])) {
              echo $this->Form->input("ParamImageRoiZ.id");
            }
            if (isset($this->data['ParamImageIndir']['id'])) {
              echo $this->Form->input("ParamImageIndir.id");
            }
            if (isset($this->data['ParamImageOutdir']['id'])) {
              echo $this->Form->input("ParamImageOutdir.id");
            }
            if (isset($this->data['ParamProjGaussSigma']['id'])) {
              echo $this->Form->input("ParamProjGaussSigma.id");
            }
            if (isset($this->data['ParamProjOutdir']['id'])) {
              echo $this->Form->input("ParamProjOutdir.id");
            }
            if (isset($this->data['ParamMisclBwYmult']['id'])) {
              echo $this->Form->input("ParamMisclBwYmult.id");
            }
            if (isset($this->data['ParamMisclBwZmult']['id'])) {
              echo $this->Form->input("ParamMisclBwZmult.id");
            }
            if (isset($this->data['ParamMisclImgYpad']['id'])) {
              echo $this->Form->input("ParamMisclImgYpad.id");
            }     
            if (isset($this->data['ParamImageClip']['id'])) {
              echo $this->Form->input("ParamImageClip.id");
            }    
            if (isset($this->data['ParamImageZ']['id'])) {
              echo $this->Form->input("ParamImageZ.id");
            }  
          }// </editor-fold>

        // ---------------------------------------------
        // ---- step ------
        // Version Name  
        $verNameOptions = array('label'=>'Version Name', 
                                'after'=>'<p class="guidance">Make this unique within this Job for best results</p>',
                                'div' => 'override_required');
        echo $this->Form->input("JobVersionName.name", $verNameOptions );
        // ------------------------------------
        // horizontal group to hold mult inputs 
        echo "<div class='horizGroup'>"; 
        // Version Number
        $verNumGuidance = '';
        $verNumOptions = array('label'=>'Version Number', 'after'=>$verNumGuidance, 'type' =>'text',
                               'div'=>'input text smallTextBoxDiv inline-block versionNum');
        echo $this->MyForm->inputsDisabledAndHidden("JobVersion.$verNum.version_num", $verNumOptions);
        // Status
        $statusOptions = array('type' =>'select', 'options'=>$statuses, 
                               'div'=>'input select smallTextBoxDiv inline-block'); 
        echo $this->MyForm->inputsDisabledAndHidden("JobVersion.$verNum.status_id", $statusOptions);
        echo "</div>";
        // end horizontal group     
        // --------------------
        // Author
        echo $this->Form->input("JobVersion.$verNum.author_id", 
                                 array('after'=>'<p class="guidance">Go ahead, take credit!</p>'));
        // Comment
        $commentOptions = array('label'=>'Comment about this version','rows' =>'2','div' => 'override_required');
        echo $this->Form->input("JobVersionComment.$commentNum.comment", $commentOptions );
        ?>
      </fieldset> <!-- end #jobVersionGeneralFieldset, .step-->
      <!-- --------- step -------------------->

      <fieldset id="jobTypeFieldset" class="step paramFieldset showFieldset tab-type">
        <legend>Type</legend>
        <?php
        // Job Type
        echo $this->MyForm->input("JobVersion.$verNum.job_type_id", 
                                   array('empty'=>'Choose...')); //, // 'type' =>'radio',
                                                                     //'legend'=>'Job Type',
                                                                     //'options'=>$jobTypes));
                //    // Shows validation error for a field
                //    if($this->Form->isFieldError("JobVersion.job_type_id")) {
                //      echo $this->Form->error("JobVersion.job_type_id");
                //    }

          ///////////////////////////////////////////////////////////////////
          ////// IMAGE PARAMETERS ///////////////////////////////////////////
        ?>
        <fieldset id="paramFdkFieldset" class="paramFieldset <?php if($showFdk) echo "showFieldset"; ?>">
            <legend>FDK Parameters</legend>
          <?php
          //////// FDK //////////
          // Filter
          $fdkFilterOptions = array('label'=>'Filter', 'empty'=>'Choose...');
          echo $this->Form->input("ParamFdkBasis.param_fdk_filter_id", $fdkFilterOptions);
          // Alpha
          $guidance = '<p class="guidance">Float between 0 and 1 inclusive</p>';
          $fdkAlphaOptions = array('label'=>'Alpha', 'after'=>$guidance);
          echo $this->Form->input("ParamFdkBasis.alpha", $fdkAlphaOptions);
          ?>
        </fieldset> <!-- end paramsFdkFieldset --> 

        <fieldset id="paramSirtFieldset" class="paramFieldset <?php if($showSirt) echo "showFieldset"; ?>">
          <legend>SIRT Parameters</legend>
          <?php
          ////// PSIRT & SIRT (shared fieldset)  ////////

          // If this version is based on an existing version, set the SirtType in the Sirt Fieldset
          $sirtTypeOptions = array('div'=>'override_required');
          if($selectSirtType_Psirt) {
            $sirtTypeOptions['selected'] = '1'; // <option> value corresponding to Psirt
          }
          else {
            $sirtTypeOptions['selected'] = '2'; // <option> value corresponding to Sirt
          }
          //echo $this->Form->input('ParamSirtBasis.sirt_type_id', $sirtTypeOptions);
          echo $this->Form->hidden('ParamSirtBasis.sirt_type_id', $sirtTypeOptions); // hidden so not showing same info twice (but needed for data array)      
          // Alpha
          $guidance = '<p class="guidance">Float between 0 and 2 exclusive</p>';
          $options  = array('label'=>'Alpha', 'after'=>$guidance, 'class'=>'sirtTextInput');
          echo $this->Form->input('ParamSirtBasis.alpha', $options);
          // ------------------------------
          // Group: Niter & Nsubs
          echo "<div class='horizGroup'>"; 
            $divClasses = 'input text smallTextBoxDiv inline-block';
            // Niter
            $guidance = '<p class="guidance">Integer 0 or greater</p>';
            $options  = array('label'=>'# Iterations', 'after'=>$guidance, 'div'=>$divClasses);
            echo $this->Form->input('ParamSirtBasis.niter', $options);
            // Nsubs
            $guidance = '<p class="guidance">Integer 1 or greater</p>';
            $options  = array('label'=>'# Subs', 'after'=>$guidance, 'div'=>$divClasses);
            echo $this->Form->input('ParamSirtBasis.nsubs', $options);
          echo "</div>";
          // end group
          // ---------
          $options = array('class'=>'sirtSubsetSelect');
          echo $this->Form->input('ParamSirtBasis.sirt_subset_mode_x_id', $options);
          $options = array('class'=>'sirtSubsetSelect', 'options'=>$sirtSubsetModeYs);
          echo $this->Form->input('ParamSirtBasis.sirt_subset_mode_y_id', $options);
          ?>
        </fieldset> <!-- end paramSirtFieldset -->
      </fieldset> <!-- end #jobTypeFieldset, .step -->

      <fieldset id="paramImageRequiredFieldset" class="step paramFieldset showFieldset tab-image_req">
        <legend>Image (required)</legend>
        <?php
        ////// IMAGE Params  ////////
        // -------------------------
        // Nx,Ny,Nz horizontal group 
        echo "<div class='horizGroup'>";
          $NxDivClasses = 'input text smallTextBoxDiv inline-block';
          $imageNxOptions = array('label'=>'Image Nx', 'after'=>'<p class="guidance">Unsigned Integer</p>',
                                  'div'  =>$NxDivClasses);
          echo $this->Form->input("JobVersion.$verNum.param_image_nx", $imageNxOptions);
          $imageNyOptions = array('label'=>'Image Ny', 'after'=>'<p class="guidance">Unsigned Integer</p>',
                                  'div'  =>$NxDivClasses);
          echo $this->Form->input("JobVersion.$verNum.param_image_ny", $imageNyOptions);
          $imageNzOptions = array('label'=>'Image Nz', 'after'=>'<p class="guidance">Unsigned Integer</p>',
                                  'div'  =>$NxDivClasses);
          echo $this->Form->input("JobVersion.$verNum.param_image_nz", $imageNzOptions);
        echo "</div>";
        // end Nx,Ny,Nz horizontal group     
        // -----------------------------
        ?>
        <fieldset id="comproiFieldset">
          <legend>Comproi Settings</legend>
          <?php
          // ------------------------------
          // COMPROI PARAM horizontal group
          $comproiTextDivClasses = 'input text smallTextBoxDiv inline-block';
          echo "<div class='horizGroup'>"; 
          // Comproi type
          $divClasses = $comproiTextDivClasses . ' comproiType';
          $comproiTypeOptions = array('label'=>'Comproi Type', 'div'=>$divClasses );
          echo $this->Form->input("JobVersion.$verNum.param_image_comproi_type_id", $comproiTypeOptions);
          // FOA Threshold
          $divClasses = $comproiTextDivClasses . ' foaThreshold';
          $foaThresholdOptions = array('label'=>'FOA Threshold', 'div'=>$divClasses);
          echo $this->Form->input("JobVersion.$verNum.param_image_foa_threshold", $foaThresholdOptions);
          // FOA Outside Max
          $divClasses = $comproiTextDivClasses . ' foaOutside';
          $foaOutsidemaxOptions = array('label'=>'FOA OutsideMax', 'div'=>$divClasses);
          echo $this->Form->input("JobVersion.$verNum.param_image_foa_outsidemax", $foaOutsidemaxOptions);
          echo "</div>";
          // end Comproi param horizontal group     
          // ----------------------------------
          ?>
        </fieldset> <!-- end Comproi nested fieldset -->
        <?php
        // Image type (U16, F32, FITS, PGM)
        $imageTypeOptions = array('label'=>'Image Type');
        echo $this->Form->input("JobVersion.$verNum.param_image_type_id", $imageTypeOptions);
        // --------------------------------
        // VOXEL dxy, dz   horizontal group  
        echo "<div class='horizGroup'>"; 
          $dxyDivClasses = 'input text smallTextBoxDiv inline-block';
          $guidance = '<p class="guidance">Non-negative float</p>';
          // dxy
          $dxyOptions = array('label'=>'Voxel dxy', 'after'=>$guidance, 'div'=>$dxyDivClasses);
          echo $this->Form->input("JobVersion.$verNum.param_image_dxy", $dxyOptions);
          // dz
          $dzOptions = array('label'=>'Voxel dz', 'after'=>$guidance, 'div'=>$dxyDivClasses);
          echo $this->Form->input("JobVersion.$verNum.param_image_dz", $dzOptions);
        echo "</div>";
        // end Image dxy, dz (Voxel) horizontal group     
        // -----------------------------
        ?>
      </fieldset> <!-- end #paramImageRequiredFieldset, .step -->
      <!-- -------- step ------ -->

      <fieldset id="paramImageOptionalFieldset" class="step paramFieldset showFieldset tab-image_opt">
        <legend>Image (optional)</legend>
        <?php
        // --------------------------------
        // CLIP   group  
        echo "<div class='horizGroup'>"; 
          $CLIP_group_guidance = 'Note: If either Clip field is left blank, no Clip parameters will be saved!';
          echo   "<p class='guidance'>$CLIP_group_guidance</p>";
          $divClasses = 'input text smallTextBoxDiv inline-block override_required';
          $guidance = '<p class="guidance"></p>';
          // clipmin
          $options = array('label'=>'Clip min', 'after'=>$guidance, 'div'=>$divClasses);
          echo $this->Form->input("ParamImageClip.clipmin", $options);
          // clipmax
          $options = array('label'=>'Clip max', 'after'=>$guidance, 'div'=>$divClasses);
          echo $this->Form->input("ParamImageClip.clipmax", $options);
        echo "</div>";
        // end CLIP group     
        // -----------------------------
        // ------------------------
        // ROI Z   horizontal group  
        echo "<div class='horizGroup'>";
          $ROI_group_guidance = 'Note: If either ROI Z field is left blank, no ROI Z parameters will be saved!';
          echo   "<p class='guidance'>$ROI_group_guidance</p>";
          // Roi Z 0
          $roizDivClasses = 'input text smallTextBoxDiv inline-block override_required';
          $guidance = '<p class="guidance">Integer 1 or greater</p>';
          $roiz0Options = array('label'=>'ROI Z 0', 'after'=>$guidance, 'div'=>$roizDivClasses);
          echo $this->Form->input("ParamImageRoiZ.roi_z_0", $roiz0Options);
          // Roi Z 1
          $guidance = '<p class="guidance">Integer</p>';
          $roiz1Options = array('label'=>'ROI Z 1', 'after'=>$guidance, 'div'=>$roizDivClasses);
          echo $this->Form->input("ParamImageRoiZ.roi_z_1", $roiz1Options);
        echo "</div>";
        // end ROI Z horizontal group     
        // --------------------------
        // Image Indir
        $divClasses = 'input text override_required';
        $placeholder = '(relative to Job Version dir)';
        $options = array('label'=>'Image Input Directory', 'div'=>$divClasses, 'placeholder'=>$placeholder);
        echo $this->Form->input("ParamImageIndir.indir", $options);
        // Image Outdir
        $options = array('label'=>'Image Output Directory','div'=>$divClasses);
        //echo $this->Form->input("ParamImageOutdir.outdir", $options);
        echo $this->MyForm->inputsDisabledAndHidden("ParamImageOutdir.outdir", $options);
        // ------------------------
        // IMG Z   group  
        echo "<div class='horizGroup'>";
          $group_guidance = 'Note: If either Image Z field is left blank, no Image Z parameters will be saved!';
          echo   "<p class='guidance'>$group_guidance</p>";
          // Img Z 0
          $divClasses = 'input text smallTextBoxDiv inline-block override_required';
          $guidance = '<p class="guidance">Integer</p>';
          $options = array('label'=>'Image Z 0', 'after'=>$guidance, 'div'=>$divClasses);
          echo $this->Form->input("ParamImageZ.out_z_0", $options);
          // Img Z 1
          $guidance = '<p class="guidance">Integer</p>';
          $options = array('label'=>'Image Z 1', 'after'=>$guidance, 'div'=>$divClasses);
          echo $this->Form->input("ParamImageZ.out_z_1", $options);
        echo "</div>";
        // end IMG Z group     
        // --------------------------
        ?>
      </fieldset> <!-- end #paramImageOptionalFieldset, .step -->
      <!-- -------- step ------ -->

      <fieldset id="paramProjFieldset" class="step paramFieldset showFieldset tab-projection">
        <legend>Projection</legend>
        <?php
        ////////// PROJ Params  ////////
        // Proj Indir
        $guidance = "<p class='guidance'>Relative to Job Version dir</p>";
        $options = array('label'=>'Projection Input Directory', 'after'=>$guidance);
        echo $this->Form->input("JobVersion.$verNum.param_proj_indir", $options);
        // Proj Outdir
        $guidance = "<p class='guidance'>Relative to Job Version dir</p>";
        $divClasses = 'input text override_required';
        $options = array('label'=>'Projection Output Directory', 'div'=>$divClasses, 'after'=>$guidance);
        echo $this->Form->input("ParamProjOutdir.outdir", $options);
        // Step
        $guidance = "<p class='guidance'>Integer 1 or greater</p>";
        $divClasses = 'input text smallTextBoxDiv';
        $options = array('label'=>'Step', 'div'=>$divClasses, 'after'=>$guidance);
        echo $this->Form->input("JobVersion.$verNum.param_proj_step", $options);
        // Apply Medianfilter
        $divClasses = 'input checkbox override_required';
        $options = array('label'=>'Apply Median filter?', 'div'=>$divClasses);
        echo $this->Form->input("JobVersion.$verNum.param_proj_apply_medianfilter", $options);
        // Apply Gaussianfilter
        $divClasses = 'input checkbox override_required';
        $options = array('label'=>'Apply Gaussian filter?', 'div'=>$divClasses);
        echo $this->Form->input("JobVersion.$verNum.param_proj_apply_gaussianfilter", $options);
        // Gaussian Sigma
        echo "<div id='gaussianSigmaDiv' ";  if($applyGaussianFilter) echo "class='show'"; echo ">";
          $guidance = "<p class='guidance'>Req if applying Gaussian Filter</p>";
          $divClasses = 'input text smallTextBoxDiv';
          $options = array('label'=>'Gaussian Sigma', 'div'=>$divClasses, 'after'=>$guidance);
          echo $this->Form->input("ParamProjGaussSigma.gauss_sigma", $options);
        echo "</div>";
        // Apply Downsampling
        $divClasses = 'input checkbox override_required';
        $options = array('label'=>'Apply Downsampling?', 'div'=>$divClasses);
        echo $this->Form->input("JobVersion.$verNum.param_proj_apply_downsampling", $options);  
        ?>
      </fieldset> <!-- end #paramProjFieldset, .step -->  
      <!-- -------- step ------ -->    

      <fieldset id="paramMisclFieldset" class="step paramFieldset showFieldset tab-misc">
        <legend>Misc</legend>
        <?php
        ////////// MISCL Params  ////////
        // Reserror
        $divClasses = 'input checkbox override_required';
        $options = array('label'=>'Apply Reserror?', 'div'=>$divClasses);
        echo $this->Form->input("JobVersion.$verNum.param_miscl_reserror", $options);
        // ---------------
        // BW Mult & Image Y Pad  group
        echo "<div class='horizGroup'>";
          $guidance = "<p class='guidance'>Integer</p>";
          $divClasses = 'input text smallTextBoxDiv override_required inline-block';
          $options = array('label'=>'Image Y Pad', 'div'=>$divClasses, 'after'=>$guidance);
          echo $this->Form->input("ParamMisclImgYpad.img_ypad", $options);
          $options = array('label'=>'BW Y Mult', 'div'=>$divClasses, 'after'=>$guidance);
          echo $this->Form->input("ParamMisclBwYmult.bw_ymult", $options);
          $options = array('label'=>'BW Z Mult', 'div'=>$divClasses, 'after'=>$guidance);
          echo $this->Form->input("ParamMisclBwZmult.bw_zmult", $options);
        echo "</div>";
        // end BW Mult group
        // -----------------
        ?>
        <fieldset id='cudaFieldset'>
          <legend>CUDA Parameters</legend>
          <?php
          // "Ready to Submit to Cuda"?
          $guidance = "<p class='guidance'>Unchecking will save the Job but not submit it to the cluster right now</p>";
              //$divClasses = 'input text smallTextBoxDiv override_required inline-block';
          $options = array('type'=>'checkbox', 'after'=>$guidance, 'checked'=>true, 
                           'name'=>'data[submitToCluster]', 'id'=>'submitToCluster');
          echo $this->Form->input("Ready to submit this job to the cluster?", $options);

                //    // "Email you when cluster job starts and ends"?
                //    echo "<div id='sendEmailDiv'>";
                //      $guidance = "<p class='guidance'>(Not yet implemented) Will be sent to: [author's email stored in db]</p>";
                //      $divClasses = 'input checkbox';
                //      $options = array('type'=>'checkbox', 'after'=>$guidance, 'checked'=>false, 
                //                       'name'=>'data[sendEmail]', 'id'=>'sendEmail');
                //      echo $this->Form->input("Email you when cluster job starts and ends?", $options);
                //    echo "</div>";

          // Cuda Wall Time
          echo "<div id='cudaWallTimeDiv'>";
            $guidance = "<p class='guidance'>Hours:Minutes:Seconds</p>";
            $divClasses = 'input';
            $options = array('type'=>'text', 'after'=>$guidance, 'value'=>"10:00:00", 
                             'name'=>'data[cudaWallTime]', 'id'=>'cudaWallTime');
            echo $this->Form->input("Cuda Wall Time", $options); 
          echo "</div>";
        ?>
        </fieldset> <!-- end #cudaFieldset -->
      </fieldset> <!-- end #paramMisclFieldset, .step -->  
      
      <!-- this blank div fixes issue of second-to-last fieldset wrapping underneath -->
      <div class="step"> </div>
      
     </div> <!-- end #slidingFormFieldsetDiv -->
    </div> <!-- end #steps -->
    
    <!-- Sliding Form NAVIGATION -->
    <div id="navigation" style="display:none;">
      <ul>
        <li class="selected">
          <a href="#" class="general">General</a>
        </li>
        <li>
          <a href="#" class="type">Type</a>
        </li>
        <li>
          <a href="#" class="image_req">Image (Req)</a>
        </li>
        <li>
          <a href="#" class="image_opt">Image (Opt)</a>
        </li>
        <li>
          <a href="#" class="projection">Projection</a>
        </li>
        <li>
          <a href="#" class="misc" >Misc</a>
        </li>
      </ul>
    </div> <!-- end #navigation (sliding form nav) -->
  <!--  
  </fieldset> <!-- end jobVersionFieldset -->
  
  </div> <!-- end jobVersionFieldset -->
  <?php ///////////////////////////////////////// 
  endif; // end if($addNewJobVersion || $editJobVersion) ///////////
  ?>
  
  </div> <!-- end #accordianWrapper -->
  
  
  
  
  
  <!-- handling the entire SUBMIT BUTTON manually for finer control -->
  <div class="submit">
    <?php
    //////////////////////////////////////////
    // Configure SUBMIT BUTTON and its tooltip
    $disabledStr = '';
    if($addNewJob && $validated) $disabledStr = 'disabled="disabled"';
    $classStr = '';
    if($addNewJob && $validated) $classStr = 'class="disabledSubmit"';
    
    $submitButtonStr = "<input $disabledStr $classStr type='submit' value='Submit' />";
    $tooltipBody = "You must start by selecting the job group and job name. If you don't see your group, it"
            ." has not been added to the database. If you don't see your job, its dir has not been created.";
    $tooltipHeader = "";
    if($addNewJob && $validated) {
      // output the submit btn and all needed stuff for the tooltip
      echo $this->Tooltip->warning($submitButtonStr, $tooltipBody, $tooltipHeader);
    }
    // If the job did not validate, the job group and job name will already be selected in the returned
    // form, so we don't need to tell the user that those must be selected, so no tooltip.
    else {
      echo $this->Form->end('Submit');
    }
    ?>
  </div> <!-- end .submit div -->
  
</div> <!-- end ".jobs form" div  -->

<div id="Fiji_Div"> <!-- to be filled in by AJAX result -->
</div>
<!-- Job heading & wrapper panel to be displayed if only adding new JobVersion -->
<?php if( !$addNewJob && !$editJob): ?>
</div> <!-- end outer panel -->
<?php endif; ?>